class Exemplar < ActiveRecord::Base
  belongs_to :project
  has_attachment :storage => :file_system, :path_prefix => 'uploads/exemplars'
  

  def grid_data
    read_file_params && @grid_data
  end
  
  def file_type
    read_file_params && @file_type
  end
  
  protected
  
  def read_file_params
    return true if @file_type && @grid_data
    
    File.open(self.full_filename) do |f|
      reader = Eprime::Reader.new(f)
      @grid_data = reader.eprime_data
      @file_type = reader.type
    end
    true
  end
  
end
